﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="BaseController.cs" company="DissingNellemann">
//   
// All rights reserved </copyright>
// <summary>
//   The i controller.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace Website.Controllers
{
    using System.Web.Mvc;

    /// <summary>
    ///     The i controller.
    /// </summary>
    public class BaseController : Controller
    {
        // GET: /I/
        #region Public Methods and Operators

        /// <summary>
        /// The init.
        /// </summary>
        /// <param name="name">
        /// The name.
        /// </param>
        public void Init(string name)
        {
            this.Session["CurrentMenuSelection"] = name;
            this.Session["CurrentSubMenuSelection"] = string.Empty;
            this.Session["SubMenuItems"] = null;
        }


        protected override void OnException(ExceptionContext filterContext)
        {
            if (filterContext.Exception.GetType() == typeof(Models.Exceptions.NotLoggedInException))
            {
                var helper = new UrlHelper(filterContext.RequestContext);
                string url = helper.Action("Login", "Account", new { msg = "Log venligst på systemet igen." });
                filterContext.Result = new RedirectResult(url);
                filterContext.ExceptionHandled = true;
            }
            else
            {
                base.OnException(filterContext);
            }
        }


      
        #endregion
    }
}